.TH std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator) 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator) \- std::filesystem::begin(directory_iterator),std::filesystem::end(directory_iterator)

.SH Synopsis
   Defined in header <filesystem>
   directory_iterator begin( directory_iterator iter ) noexcept; \fB(1)\fP \fI(since C++17)\fP
   directory_iterator end( directory_iterator ) noexcept;        \fB(2)\fP \fI(since C++17)\fP

   1) Returns iter unchanged.
   2) Returns a default-constructed directory_iterator, which serves as the end
   iterator. The argument is ignored.

   These non-member functions enable the use of directory_iterators with range-based
   for loops
   and make directory_iterator a range type
   \fI(since C++20)\fP.

.SH Parameters

   iter - a directory_iterator

.SH Return value

   1) iter unchanged.
   2) End iterator (default-constructed directory_iterator).

.SH Example


// Run this code

 #include <filesystem>
 #include <fstream>
 #include <iostream>
 namespace fs = std::filesystem;

 int main()
 {
     fs::create_directories("sandbox/a/b");
     std::ofstream("sandbox/file1.txt");
     std::ofstream("sandbox/file2.txt");
     for (auto& p : fs::directory_iterator("sandbox"))
         std::cout << p << '\\n';
     fs::remove_all("sandbox");
 }

.SH Possible output:

 "sandbox/a"
 "sandbox/file1.txt"
 "sandbox/file2.txt"

   Defect reports

   The following behavior-changing defect reports were applied retroactively to
   previously published C++ standards.

      DR    Applied to       Behavior as published             Correct behavior
   LWG 3480 C++17      end took the argument by reference takes the argument by value

.SH See also

   begin(std::filesystem::recursive_directory_iterator) range-based for loop support
   end(std::filesystem::recursive_directory_iterator)   \fI(function)\fP
